package se.liu.johfa428.game.objects.levelselection;

import se.liu.johfa428.game.objects.intro.ObjectEndOfGame;
import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.world.interfaces.InputAction;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.model.WorldInput;
import se.liu.oschi129.world.objects.WorldObject;
import se.liu.oschi129.world.objects.WorldStaticObject;

/**
 * This object is the Castle in the level selection world.
 * 
 * @author johfa428
 */
public class ObjectLevelSelectionCastle extends WorldStaticObject implements InputAction{

	private boolean loadLevel = false;	
	
	public ObjectLevelSelectionCastle(double x, double y) {
		super(Type.SOFT, AnimationSpace.get("img_castle"), true, x, y, 58/2,70/2);
	}

	public ObjectLevelSelectionCastle(){
		this(0, 0);
	}
	
	public void performInputAction(WorldInput input) {
		if (input.jumpDown())
			loadLevel = true;
	}

	@Override public void performStepAction(World world) {
		if (loadLevel){
			loadLevel = false;
			for ( WorldObject other : world.getObjects()){
				if(other instanceof ObjectLevelSelectionPlayer && collision(other)){
					world.setWidth(320);
					world.setHeight(240);
					world.pushSyncrhonized();
					world.addObjectSynchronized(new ObjectEndOfGame(world));
					world.addInteractiveObjectSynchronized(new ObjectEndOfGame(world));
				}
			}			
			
		}
	}


}


